﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
namespace ERP.Classes
{
    public class cs_erp_hh_ttInfo
    {
        private int _id_thuoctinh;
        private int _id_hh;
        private string _tenkythuat;
        private bool _sudung;

        public cs_erp_hh_ttInfo()
        {
            this._id_thuoctinh = 0;
            this._id_hh = 0;
            this._tenkythuat = " ";
            this._sudung = true;

        }
        public int id_thuoctinh
        {
            get
            {
                return this._id_thuoctinh;
            }
            set
            {
                this._id_thuoctinh = value;
            }
        }
        public int id_hh
        {
            get
            {
                return this._id_hh;
            }
            set
            {
                this._id_hh = value;
            }
        }
        public string tenkythuat
        {
            get
            {
                return this._tenkythuat;
            }
            set
            {
                this._tenkythuat = value;
            }
        }
        public bool sudung
        {
            get
            {
                return this._sudung;
            }
            set
            {
                this._sudung = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[5];
            paraName[0] = "@id_thuoctinh";
            paraName[1] = "@id_hh";
            paraName[2] = "@tenkythuat";
            paraName[3] = "@sudung";
            paraName[4] = "@option";
            object[] paraValue = new object[5];
            paraValue[0] = this._id_thuoctinh;
            paraValue[1] = this._id_hh;
            paraValue[2] = this._tenkythuat;
            paraValue[3] = this._sudung;
            paraValue[4] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 5, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_ERP_HH_TT", option);
        }

        
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_HH_TT", "id_thuoctinh = " + this._id_thuoctinh + " and id_hh = " + this._id_hh);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_thuoctinh = Convert.ToInt32(ds.Tables[0].Rows[0]["id_thuoctinh"].ToString().Trim());
                this._id_hh = Convert.ToInt32(ds.Tables[0].Rows[0]["id_hh"].ToString().Trim());
                this._tenkythuat = ds.Tables[0].Rows[0]["tenkythuat"].ToString().Trim();
                this._sudung = Convert.ToBoolean(ds.Tables[0].Rows[0]["sudung"].ToString().Trim());
                return 1;
            }
            catch
            {
                return -1;
            }
        }
        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select id_thuoctinh, id_hh, tenkythuat, sudung "
                + " from ERP_HH_TT";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }
    }
}